﻿Imports ModuloFinanceiro
Imports ModuloVendas
Imports ModuloEstoque
Imports VendasBLL
Imports EstoqueBLL
Public Class frmPrincipal
    Public objusuario As New UsuarioBLL
    Dim InicioUC As New InicioUC
    Dim EstoqueUC As New EstoqueUC
    Dim FinanceiroUC As New FinanceiroUC
    Dim MovimentacaoUC As New MovimentacaoUC
    Dim PessoasUC As New PessoasUC
    Dim VeiculosUC As New VeiculosUC
    Dim RelatorioUC As New RelatorioUC
    Dim ObjAge As New AgendamentoBLL
    Dim funcoesuc As New FuncoesUC

    'Sub AtualizaSize()
    '    Dim Altura As Integer
    '    Dim Largura As Integer
    '    Largura = TPInicio.Size.Width.ToString
    '    Altura = TPInicio.Size.Height.ToString
    '    InicioUC.PNTop.Size = New System.Drawing.Size(Largura, (Altura / 2))
    '    InicioUC.PNLow.Size = New System.Drawing.Size(Largura, (Altura / 2))
    '    Largura = InicioUC.PNTop.Size.Width.ToString
    '    Altura = InicioUC.PNTop.Height.ToString
    '    InicioUC.PNAgendamento.Size = New System.Drawing.Size(Largura / 2, Altura)
    'End Sub

    Public Sub desetivar()
        InicioUC = New InicioUC
        EstoqueUC = New EstoqueUC
        VeiculosUC = New VeiculosUC
        FinanceiroUC = New FinanceiroUC
        MovimentacaoUC = New MovimentacaoUC
        PessoasUC = New PessoasUC
        funcoesuc = New FuncoesUC
        RelatorioUC = New RelatorioUC
        TPFinanceiro.Controls.Clear()
        TPInicio.Controls.Clear()
        TPEstoque.Controls.Clear()
        TPFinanceiro.Controls.Clear()
        TPMovimentacao.Controls.Clear()
        TPPessoa.Controls.Clear()
        TPRelatorios.Controls.Clear()
        TPVeiculos.Controls.Clear()
        TPRelatorios.Controls.Clear()
        TCMenu.SelectTab(0)
    End Sub

    Private Sub TCMenu_Selected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TCMenu.Selected
        Try
            Select Case TCMenu.SelectedTab.Text
                Case "Funções"
                    Me.funcoesuc = New FuncoesUC
                    Me.TPFuncoes.Controls.Clear()
                    Me.funcoesuc.Dock = DockStyle.Fill
                    Me.funcoesuc.usuario = objusuario
                    carrega(49, funcoesuc, "")
                    Me.TPFuncoes.Controls.Add(funcoesuc)
                Case "Relatórios"
                    Me.RelatorioUC = New RelatorioUC
                    Me.TPRelatorios.Controls.Clear()
                    Me.RelatorioUC.Dock = DockStyle.Fill
                    carrega(7, RelatorioUC, "")
                    Me.TPRelatorios.Controls.Add(RelatorioUC)
                Case "Inicio"
                    Me.InicioUC = New InicioUC
                    Me.TPInicio.Controls.Clear()
                    Me.InicioUC.Dock = DockStyle.Fill
                    carrega(1, InicioUC, "S")
                    Me.TPInicio.Controls.Add(InicioUC)
                Case "Estoque"
                    Me.EstoqueUC = New EstoqueUC
                    Me.TPEstoque.Controls.Clear()
                    Me.EstoqueUC = New EstoqueUC
                    Me.EstoqueUC.Dock = DockStyle.Fill
                    carrega(5, EstoqueUC, "")
                    Me.TPEstoque.Controls.Add(EstoqueUC)
                Case "Veículos"
                    Me.VeiculosUC = New VeiculosUC
                    Me.TPVeiculos.Controls.Clear()
                    Me.VeiculosUC = New VeiculosUC
                    Me.VeiculosUC.Dock = DockStyle.Fill
                    carrega(3, VeiculosUC, "")
                    Me.TPVeiculos.Controls.Add(VeiculosUC)
                Case "Financeiro"
                    Me.FinanceiroUC = New FinanceiroUC
                    Me.TPFinanceiro.Controls.Clear()
                    Me.FinanceiroUC = New FinanceiroUC
                    Me.FinanceiroUC.Dock = DockStyle.Fill
                    carrega(6, FinanceiroUC, "")
                    Me.TPFinanceiro.Controls.Add(FinanceiroUC)
                    Me.TPFinanceiro.AutoScroll = True
                Case "Movimentação"
                    MovimentacaoUC = New MovimentacaoUC
                    Me.TPMovimentacao.Controls.Clear()
                    Me.MovimentacaoUC = New MovimentacaoUC
                    Me.MovimentacaoUC.Dock = DockStyle.Fill
                    carrega(4, MovimentacaoUC, "")
                    Me.TPMovimentacao.Controls.Add(MovimentacaoUC)
                Case "Pessoas"
                    PessoasUC = New PessoasUC
                    Me.TPPessoa.Controls.Clear()
                    Me.PessoasUC = New PessoasUC
                    Me.PessoasUC.Dock = DockStyle.Fill
                    carrega(2, PessoasUC, "")
            End Select
            Me.TPPessoa.Controls.Add(PessoasUC)
            Catch ex As Exception
            MessageBox.Show("Erro ao carregar Lista de Permissões", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try
    End Sub

    Private Sub TPEstoque_ControlRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles TPEstoque.ControlRemoved, TPVeiculos.ControlRemoved, TPRelatorios.ControlRemoved, TPMovimentacao.ControlRemoved, TPInicio.ControlRemoved, TPFinanceiro.ControlRemoved, TCMenu.ControlRemoved, TPPessoa.ControlRemoved
        If (Not IsNothing(statustabestoque)) Then
            If (statustabestoque = "N") Then
                TCMenu_Selected(Nothing, Nothing)
                statustabestoque = Nothing
            End If
        End If
        If (Not IsNothing(statustabvendas)) Then
            If (statustabvendas = "N") Then
                TCMenu_Selected(Nothing, Nothing)
                statustabvendas = Nothing
            End If
        End If
        If (Not IsNothing(statusfinanceiro)) Then
            If (statusfinanceiro = "N") Then
                TCMenu_Selected(Nothing, Nothing)
                statusfinanceiro = Nothing
            End If
        End If
    End Sub

    Private Sub frmPrincipal_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        objusuarios = objusuario
        Me.TPInicio.Controls.Clear()
        Me.InicioUC.Dock = DockStyle.Fill
        Me.TPInicio.Controls.Add(InicioUC)
        Me.TCMenu_Selected(Nothing, Nothing)

    End Sub

    Private Sub MTCData_DateSelected(sender As System.Object, e As System.Windows.Forms.DateRangeEventArgs) Handles MTCData.DateSelected
        InicioUC.DGVAgendamento.DataSource = ObjAge.locdata(MTCData.SelectionRange.Start, MTCData.SelectionRange.Start)
    End Sub

  

#Region "carregar"
    Public Sub carrega(posicao As Integer, uc As UserControl, inicio As String)
        If (Not IsNothing(objusuario)) Then
            If (objusuario.Codigo > 0) Then
                Dim objpermissao As New PermissaoBLL
                Dim dt As New DataTable
                objpermissao.ususario = objusuario.Codigo
                dt = objpermissao.buscaritens()
                For Each item As DataRow In dt.Rows
                    Select Case Val(item("men_nivel"))
                        Case posicao
                            If (inicio = "S") Then
                                For Each contr In uc.Controls
                                    If contr.Tag = item("men_codigo") Then contr.Visible = True
                                    For Each a In contr.controls
                                        For Each b In a.controls
                                            For Each c In b.controls
                                                If c.Tag = item("men_codigo") Then c.Visible = True
                                            Next
                                        Next
                                    Next

                                Next
                            Else
                                For Each controle In uc.Controls
                                    For Each botao In controle.items
                                        If botao.tag = item("men_codigo") Then botao.visible = True
                                    Next
                                Next
                            End If


                    End Select
                Next
            End If
        End If
    End Sub
#End Region

    
End Class
